package mediator.main.colleague;

import mediator.main.mediator.IMediator;

public abstract class AbstractUser implements IUser {

    //中介者
    protected IMediator mediator;
    //姓名
    protected String name;
    //消息
    protected String message;

    public AbstractUser(IMediator mediator, String name) {
        this.mediator = mediator;
        this.name = name;
    }


    /**
     * 发送消息
     *
     * @param message
     */
    @Override
    public void sendMessage(String message) {
        this.message = message;
        System.out.println(String.format("%s说%s", this.name, this.message));
        mediator.notifyAllMessage(this);
    }

    /**
     * 获得发送的消息内容
     */
    @Override
    public String getMessage() {
        return message;
    }
}
